package com.dc.designPattern._5_adapter._4_demo_mvc;

/**
 * Description: 适配器模式Demo_SpringMvc_处理适配器
 * @author: gdc
 * @date: 2021/3/11
 * @version 1.0
 */
public interface HandlerAdapter {
    /**
     * 是否能处理
     * @param handler           处理对象
     * @return                  结果
     */
    boolean supports(Object handler);

    /**
     * 处理业务
     * @param handler           处理对象
     */
    void handle(Object handler);
}


class HttpHandlerAdapter implements HandlerAdapter{
    @Override
    public boolean supports(Object handler) {
        return handler instanceof HttpController;
    }

    @Override
    public void handle(Object handler) {
        ((HttpController) handler).doHandler();
    }
}

class SimpleAdapter implements HandlerAdapter{
    @Override
    public boolean supports(Object handler) {
        return handler instanceof SimpleController;
    }

    @Override
    public void handle(Object handler) {
        ((SimpleController) handler).doHandler();
    }
}

class AnnotationAdapter implements HandlerAdapter{
    @Override
    public boolean supports(Object handler) {
        return handler instanceof AnnotationController;
    }

    @Override
    public void handle(Object handler) {
        ((AnnotationController) handler).doHandler();
    }
}


